package com.cos.lession77.web.controller;

import com.cos.lession77.entity.Emp;
import com.cos.lession77.service.EmpServices;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: COS
 * @time: 2022/10/10 9:25
 * @description:
 */
@RestController
@RequestMapping("/emp")
@Api(value = "处理员工相关请求的控制类",tags = "EmpController")
public class EmpController {
    @Autowired
    private EmpServices empServices;

    @ApiOperation("使用员工主键获取员工信息")
    @ApiParam(value = "eno",name = "eno",required = true,example = "1001")
    @GetMapping("/getEmpByEno/{eno}")
    public Emp getEmpByEno(@PathVariable("eno") Integer eno) {
        return empServices.getEmpByEno(eno);
    }
    @ApiOperation("新增员工信息")
    @PostMapping("/addEmp")
    public String addEmp(@RequestBody Emp emp) {
        if (empServices.addEmp(emp)) {
            return "1";
        }
        return "0";
    }
    @ApiOperation("修改员工信息")
    @PutMapping("/updateEmp")
    public String updateEmp(@RequestBody Emp emp) {
        if (empServices.updateEmp(emp)) {
            return "1";
        }
        return "0";
    }
    @ApiOperation("登录操作")
    @PostMapping("/login")
    public String doLogin(String ename ,String pwd) {
        //es
        return "1";
    }
    @ApiOperation("获取所有员工信息")
    @GetMapping("/getAll")
    public List<Emp> getAll() {
        return empServices.getAll();
    }
    @ApiOperation("分页获取员工信息")
    @GetMapping("/getByPage")
    public PageInfo<Emp> getEmpByPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                      @RequestParam(defaultValue = "5") Integer pageSize) {
        return empServices.getEmpByPage(pageNum, pageSize);
    }
    @ApiOperation("删除员工信息")
    @DeleteMapping("/delEmp/{eno}")
    public String delEmp(@PathVariable("eno") Integer eno) {
        if (empServices.delEmp(eno)) {
            return "1";
        } else {
            return "0";
        }
    }
}
